<template>
	<view class="footer view">
		<view @click="toIndex" class="navi" :style="{color: routes =='pages/index/index'?'white':'#b9b9b9'}">首页</view>
		<image class="image" src="https://yy.dx1126.cn/images/tianjia.png" mode="" @click="setXiangjie"></image>
		<view @click="toMy" class="navi" :style="{color: routes=='pages/my/my'?'white':'#b9b9b9'}">
			我的
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		watch,
		getCurrentInstance
	} from 'vue'
	import {
		useIndexStore
	} from '@/store/pinia.js';
	let store = useIndexStore()

	let that = getCurrentInstance()
	let pages = getCurrentPages()
	let names = pages[0].__route__
	let routes = ref(names)

	const toIndex = () => {
		if (routes.value == "pages/index/index") {
			return
		}
		uni.redirectTo({
			url: "/pages/index/index"
		})
		store.randomVideo()
	}
	const toMy = () => {
		if (routes.value == "pages/my/my") {
			return
		}
		uni.redirectTo({
			url: "/pages/my/my"
		})
	}

	// 获取摄像头权限
	const setXiangjie = (e) => {
		uni.authorize({
			scope: 'scope.camera',
			success() {
				uni.showToast({
					title: '已获取相机权限',
					duration: 2000
				});
				uni.redirectTo({
					url: "/pages/addVideo/addVideo"
				})
			},
			fail() {
				uni.showToast({
					title: '未获取相机权限，无法拍摄',
					icon: 'error',
					duration: 2000
				});
			}
		})
	}
</script>

<style lang="less" scoped>
	.footer {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		background-color: #000000;
		transition: all 0.5 ease-in-out;

		.image {
			width: 60rpx;
			height: 60rpx;
		}

		.navi {
			color: #b9b9b9;
		}
	}
</style>